iT邦幫忙

2021 iThome 鐵人賽

DAY 8
0
Software Development

LINE機器人學習歷程系列 第 8

[DAY8]將範例上傳(2)

  • 分享至 

  • xImage
  •  

第一步:將昨天下載完的壓縮檔解壓縮,取出line-bot-sdk-python-master\examples中的flask-echo資料夾將其中資料和Linebot資料夾轉移至我們創立的資料夾
https://ithelp.ithome.com.tw/upload/images/20210922/20140159LWHlc8pCoU.png
https://ithelp.ithome.com.tw/upload/images/20210922/201401598lTocGCyF2.png
第二步:編輯app.py
https://ithelp.ithome.com.tw/upload/images/20210922/20140159DO6Y97H5Aw.jpg
更改紅框內的內容將其改成在LINE提供的channel_secret和channel_access_token(可於LINE Developer尋找),於def callback副程式內加上print(body)
將flask,future,requests, line_bot_sdk,gunicorn, psycopg這些字串放入requirements.txt檔裡面讓Heroku記得下載
https://ithelp.ithome.com.tw/upload/images/20210922/20140159Tx7lmtTUi3.png
第三步:回到CMD

  1. 輸入heroku login
    https://ithelp.ithome.com.tw/upload/images/20210922/20140159sztLXzOOg6.png
    按下Log in後關閉
  2. 輸入heroku git:remote -a {Heroku專案名}
  3. 輸入git init
  4. 輸入git add .
  5. 輸入git commit -am'ok'
  6. 最後輸入git push heroku master
PS F:\課業\juclinebot\juctest> heroku login
 »   Warning: heroku update available from 7.53.0 to 7.56.1.
heroku: Press any key to open up the browser to login or q to exit: 
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/acc9faa8-807c-49c3-aad3-df1f897d13c3?requestor=SFMyNTY.g2gDbQAAAA4xMTguMTUwLjEyNS42NG4GADCf_Qp8AWIAAVGA.UxxAOnDfwa6LFXrKpiyhZzod7g7PE1m94BbzcfUJioY
Logging in... done
Logged in as juc097676907@gmail.com
PS F:\課業\juclinebot\juctest>
PS F:\課業\juclinebot\juctest> heroku git:remote -a juctest
 »   Warning: heroku update available from 7.53.0 to 7.56.1.
set git remote heroku to https://git.heroku.com/juctest.git
PS F:\課業\juclinebot\juctest> git init
PS F:\課業\juclinebot\juctest> git add .
PS F:\課業\juclinebot\juctest> git commit -am'ok'
[master 8ede0b8] ok
 Committer: cscs020 <rusa020@easybuy3c.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)
PS F:\課業\juclinebot\juctest> git push heroku master      
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 390 bytes | 390.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/python
remote: -----> Python app detected
remote: -----> No Python version was specified. Using the same version as the last build: python-3.9.6
remote:        To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
remote:  !     Python has released a security update! Please consider upgrading to python-3.9.7
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> No change in requirements detected, installing from cache
remote: -----> Using cached install of python-3.9.6
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 57.6M
remote: -----> Launching...
remote:        Released v76
remote:        https://juctest.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/juctest.git
   a14adf9..8ede0b8  master -> master

第四步:回到LINE Developer更改webhook
改成https://{hereku專案名}.herokuapp.com/callback
https://ithelp.ithome.com.tw/upload/images/20210922/20140159kVtf3hnAHZ.jpg
將Use webhook打開,關閉Auto-reply messages 。
第五步:拿起LINE掃描QRcode將機器人加入好友並傳送訊息
https://ithelp.ithome.com.tw/upload/images/20210922/20140159KVnGnrdp4R.png
成功QAQ
參考資料:
LINE Bot聊天機器人程式開發教學(二):註冊與設定Heroku平台應用程式 - 超圖解系列圖書
使用 Heroku 建立範例聊天機器人 | LINE Developers
LineBot+Python,輕鬆建立聊天機器人 | BlackMaple's Blog
(376) 【Maso的萬事屋】10分鐘用Python做LineBot聊天機器人|程式設計 - YouTube


上一篇
[DAY7]將範例上傳(1)
下一篇
[DAY9]觀察heroku logs
系列文
LINE機器人學習歷程30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言